package com.itheima.bianma;

import java.io.UnsupportedEncodingException;
import java.util.Arrays;

public class Demo01 {

    public static void main(String[] args) throws UnsupportedEncodingException {
        //String-> byte[]
        String  s="魑魅魍魉";
        byte[] bytes = s.getBytes();//[-23, -83, -111, -23, -83, -123, -23, -83, -115, -23, -83, -119]
        byte[] gbks = s.getBytes("gbk");//[-9, -50, -9, -56, -9, -51, -9, -53]
        System.out.println(Arrays.toString(bytes));
        System.out.println(Arrays.toString(gbks));
        //byte[] ->String
        byte[] bytes1={-23, -83, -111, -23, -83, -123, -23, -83, -115, -23, -83, -120};
        String s1 = new String(bytes1,"gbk");
        System.out.println(s1);

        byte[] bytes2={-9, -50, -9, -56, -9, -51, -9, -54};
        String gbk = new String(bytes2);
        System.out.println(gbk);


    }
}
